using System;
using System.Collections.Generic;
using System.Linq;
namespace WebClient.Controllers
{
	#region using
	using System.Web.Mvc;
	using WebClient.Models.ViewModels;
	using WebClient.Models;
	using WebClient.Models.Repositories;
	using WebClient.Helpers;
	using System.Web.Security;
    using WebClient.CF_DAL_WS;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectFoodType()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_FOODTYPE
			};
			return View(CreateViewModel(data));
		}



		public ActionResult DeleteFoodType(int id, int page = 1)
		{
			var result = _repFoodType.Delete(id);
			var data = new DataTransferViewModel
			{
				InfoText = result ? "Item has been deleted" : "Cannot delete item!",
				EnumViewModelType = EnumViewModel.ADMIN_FOODTYPE,
				CurrentPage = page
			};
			return View("SelectFoodType", CreateViewModel(data));
		}

		public ActionResult EditFoodType(int page, int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_FOODTYPE,
				CurrentPage = page,
				IntID = id
			};
			return PartialView("Templates/TH_EditFoodType", CreateViewModel(data));
		}

		public ActionResult CancelEditingFoodType(int page)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_FOODTYPE,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListFoodType", CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateFoodType(FormCollection forms)
		{
			string id = forms.GetValues("FoodType_ID")[0];
			string name = forms.GetValues("FoodType_Name")[0];
			var foodtype = _repFoodType.SelectByID(int.Parse(id));
			foodtype.Name = name;
			var result = _repFoodType.Update(foodtype);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_FOODTYPE,
			};
			return View("SelectFoodType", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertFoodType(FormCollection forms)
		{
			string name = forms.GetValues("FoodType_Name")[0];
			var newItem = new FoodTypeDTO
			{
				Name = name
			};
			var result = _repFoodType.Insert(newItem);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_FOODTYPE,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectFoodType", CreateViewModel(data));
		}


	}
}